package BehavioralPatterns.ChainOfResponsibility;

/*
意图：避免请求发送者与接收者耦合在一起，让多个对象都有可能接收请求，将这些对象连接成一条链，并且沿着这条链传递请求，直到有对象处理它为止。
 */
public abstract class AbstractLogger {

  public static int INFO = 1;
  public static int DEBUG = 2;
  public static int ERROR = 3;

  protected int level;

//  责任链下一个元素
  public AbstractLogger nextLogger;

  public void setNextLogger(AbstractLogger nextLogger) {
    this.nextLogger = nextLogger;
  }

  public void logMessage(int level,String message){
    if (this.level <= level){
      write(message);
    }
    if (nextLogger != null){
      nextLogger.logMessage(level,message);
    }
  }

  abstract void write(String message);
}
